home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 019 / keymap_test / keymap_test.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  7KB  |  233 lines

  1. /*******  keymap_test.c  **********/
  2.  
  3. /***************************************************************************
  4.  *
  5.  *             Test program to illustrate bug in keymapping
  6.  *
  7.  **************************************************************************/
  8.  
  9.  
  10. #include "keymap_test.h"
  11.  
  12.  
  13. extern Enable_Abort;
  14.  
  15.  
  16. ULONG  IntuitionBase;
  17. ULONG  GfxBase;
  18. struct Window    *te_window; /* ptr to a window to which the
  19.                               * console is bound
  20.                               */
  21.  
  22. struct  NewWindow  NewWindow =
  23.    {
  24.    0, 0,                                /* starting position              */
  25.    640, 200,                            /* window width and height        */
  26.    -1, -1,                              /* use same pens as screen        */
  27.    NULL,                                /* no IDCMP flags                 */
  28.    SMART_REFRESH | BORDERLESS | ACTIVATE, /* window flags      */
  29.    NULL, NULL, NULL,                    /* no gadgets, checkmark & text   */
  30.    NULL,                                /* pointer to screen              */
  31.    NULL,                                /* no bit map                     */
  32.    NULL, NULL, NULL, NULL,              /* window sizing parameters       */
  33.    WBENCHSCREEN,                        /* screen type                    */
  34.    };
  35.  
  36. struct IOStdReq  *con_write_req, *con_read_req;
  37. struct MsgPort   *con_write_port, *con_read_port;
  38.  
  39. UBYTE conchar;         /* used for QueueRead() */
  40.  
  41. struct KeyMap     keymap;
  42.  
  43. UBYTE lo_types[64];
  44. ULONG lo_keymap[64];
  45. UBYTE lo_cap[8];
  46. UBYTE lo_rep[8];
  47.  
  48. UBYTE hi_types[40];
  49. ULONG hi_keymap[40];
  50. UBYTE hi_cap[8];
  51. UBYTE hi_rep[8];
  52.  
  53. UBYTE string_alt_shift[] =
  54.          {
  55.          10,            /* length of string with no qualifier         */
  56.          8,             /* dist of string from beg of descriptor      */
  57.          9,             /* length of string with SHIFT                */
  58.          18,            /* dist of string from beg of descriptor      */
  59.          7,             /* length of string with ALT                  */
  60.          27,            /* dist of string from beg of descriptor      */
  61.          15,            /* length of string with ALT + SHIFT          */
  62.          34,            /* dist of string from beg of descriptor      */
  63.          "2 + noqual",
  64.          "2 + shift",
  65.          "2 + alt",
  66.          "2 + alt + shift",
  67.          };
  68.  
  69. UBYTE string_vanilla[] =
  70.          {
  71.          10,            /* length of string with no qualifier         */
  72.          16,            /* dist of string from beg of descriptor      */
  73.          9,             /* length of string with SHIFT                */
  74.          26,            /* dist of string from beg of descriptor      */
  75.          7,             /* length of string with ALT                  */
  76.          35,            /* dist of string from beg of descriptor      */
  77.          8,             /* length of string with CTRL                 */
  78.          42,            /* dist of string from beg of descriptor      */
  79.          15,            /* length of string with ALT + SHIFT          */
  80.          50,            /* dist of string from beg of descriptor      */
  81.          14,            /* length of string with CTRL + ALT           */
  82.          65,            /* dist of string from beg of descriptor      */
  83.          16,            /* length of string with CTRL + SHIFT         */
  84.          79,            /* dist of string from beg of descriptor      */
  85.          22,            /* length of string with CTRL + ALT + SHIFT   */
  86.          95,            /* dist of string from beg of descriptor      */
  87.          "3 + noqual",
  88.          "3 + shift",
  89.          "3 + alt",
  90.          "3 + ctrl",
  91.          "3 + alt + shift",
  92.          "3 + ctrl + alt",
  93.          "3 + ctrl + shift",
  94.          "3 + ctrl + alt + shift",
  95.          };
  96.  
  97. init_window()
  98. {
  99.    GfxBase = (ULONG) OpenLibrary("graphics.library", 0);
  100.    IntuitionBase = (ULONG) OpenLibrary("intuition.library", 0);
  101.    te_window = OpenWindow(&NewWindow);
  102. }
  103.  
  104.  
  105. init_req()
  106. {
  107.    con_write_port = CreatePort("my.con.write",0);
  108.    con_write_req  = CreateStdIO(con_write_port);
  109.  
  110.    con_read_port = CreatePort("my.con.read",0);
  111.    con_read_req =  CreateStdIO(con_read_port);
  112.   
  113.    OpenConsole(con_write_req, con_read_req, te_window);
  114.  
  115. }
  116.  
  117.  
  118.  
  119. main()
  120. {
  121.    UBYTE c;
  122.    int i;
  123.  
  124.  
  125.    init_window();
  126.    init_req();
  127.  
  128.    QueueRead (con_read_req, &conchar);
  129.  
  130.    /* initialize keymap tables to zeroes
  131.     */
  132.    for (i = 0; i <= 63; i++)
  133.       {
  134.       lo_types[i] = 0x00;
  135.       lo_keymap[i] = 0x00;
  136.       }
  137.  
  138.    for (i = 0; i <= 39; i++)
  139.       {
  140.       hi_types[i] = 0x00;
  141.       hi_keymap[i] = 0x00;
  142.       }
  143.  
  144.    for (i = 0; i <= 7; i++)
  145.       {
  146.       lo_cap[i] = 0x00;
  147.       lo_rep[i] = 0x00;
  148.       hi_cap[i] = 0x00;
  149.       hi_rep[i] = 0x00;
  150.       }
  151.  
  152.    /* setup key types for keys 1, 2, 3, & 4
  153.     */
  154.    lo_types[1] = 0x05;        /* KCF_CONTROL + KCF_SHIFT           */
  155.    lo_types[2] = 0x43;        /* KCF_STRING + KCF_ALT + KCF_SHIFT  */
  156.    lo_types[3] = 0x47;        /* KCF_STRING + KC_VANILLA           */
  157.    lo_types[4] = 0x01;        /* KC_NOQUAL  + KCF_SHIFT            */
  158.  
  159.  
  160.    /* setup key codes for keys 1, 2, 3, & 4
  161.     */
  162.    lo_keymap[1]   = (ULONG) 0x64636261;  /* d = key 1 with CTRL + SHIFT */
  163.                                          /* c = key 1 with CTRL         */
  164.                                          /* b = key 1 with SHIFT        */
  165.                                          /* a = key 1 alone             */
  166.    lo_keymap[2]   = (ULONG) 0x00000000;  /*     key 2                   */
  167.    lo_keymap[3]   = (ULONG) 0x00000000;  /*     key 3                   */
  168.    lo_keymap[4]   = (ULONG) 0x00002434;  /*     key 4                   */
  169.  
  170.  
  171.    /* plug in addresses of string descriptors into low keymap
  172.     */
  173.    lo_keymap[2] = (ULONG) string_alt_shift;
  174.    lo_keymap[3] = (ULONG) string_vanilla;
  175.  
  176.  
  177.    /* setup pointers to members of keymap structure
  178.     */
  179.    keymap.km_LoKeyMapTypes = (APTR) lo_types;
  180.    keymap.km_LoKeyMap      = (APTR) lo_keymap;
  181.    keymap.km_LoCapsable    = (APTR) lo_cap;
  182.    keymap.km_LoRepeatable  = (APTR) lo_rep;
  183.    keymap.km_HiKeyMapTypes = (APTR) hi_types;
  184.    keymap.km_HiKeyMap      = (APTR) hi_keymap;
  185.    keymap.km_HiCapsable    = (APTR) hi_cap;
  186.    keymap.km_HiRepeatable  = (APTR) hi_rep;
  187.  
  188.    /* Now set the new keymap
  189.     */
  190.    con_write_req-> io_Command = CD_SETKEYMAP;
  191.    con_write_req-> io_Length  = sizeof(keymap);
  192.    con_write_req-> io_Data    = (APTR) &keymap;
  193.  
  194.    DoIO (con_write_req);
  195.  
  196.    Enable_Abort = 0;
  197.  
  198.    /* Keys 1, 2 & 3 have been setup with key types 0x05, 0x43 & 0x47 
  199.     * respectively.
  200.     * Press key 4 + SHIFT to exit
  201.     */
  202.  
  203.     for (;;)
  204.       {
  205.       /* Note: Chk_Abort() does not work here
  206.        */
  207.  
  208.       if (Chk_Abort() != 0)
  209.          break;               /* ctrl-c or ctrl-d was pressed */
  210.       
  211.       c = (UBYTE) ConMayGetChar (con_read_req, con_read_port, &conchar);
  212.       if (c != '$')
  213.          {
  214.          ConPutChar (con_write_req, c);
  215.          }
  216.       else
  217.          break;
  218.       }
  219.  
  220.    AbortIO(con_read_req);
  221.    CloseDevice(con_read_req);
  222.  
  223.    DeletePort(con_read_port);
  224.    DeletePort(con_write_port);
  225.    DeleteStdIO(con_read_req);
  226.    DeleteStdIO(con_write_req);
  227.  
  228.    CloseWindow(te_window);
  229.    CloseLibrary(IntuitionBase);
  230.    CloseLibrary(GfxBase);
  231.  
  232. }
  233.